package whu.cn.whushare.ui.main.my;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.RadioGroup;

import com.androidplus.util.StringUtil;
import com.androidplus.util.ViewMapping;
import com.androidplus.util.ViewMappingUtil;

import whu.cn.whushare.R;
import whu.cn.whushare.common.UserManager;
import whu.cn.whushare.net.DownloadParams;
import whu.cn.whushare.net.Downloader;
import whu.cn.whushare.ui.common.BaseActivity;

/**
 * Created by xiaoping on 2015/1/30.
 */
@ViewMapping(id= R.layout.activity_myinfo_sex_change)
public class InfoSexChangeActivity  extends BaseActivity {
    @ViewMapping(id = R.id.sex_type_choice)
    private RadioGroup mSexTypeChange;
    private String gender;
    private UserManager mUserManager;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        initViewsAndActions();
    }
    public static Intent getStartIntent(Context context) {
        Intent i = new Intent(context, InfoSexChangeActivity .class);

        return i;
    }

    private void initViewsAndActions() {
        View root = ViewMappingUtil.mapView(this, this);
        getTopBar(root);
        mTopBar.title.setText(R.string.my_info_sex_change);
        mTopBar.rightText.setVisibility(View.VISIBLE);
        mTopBar.rightText.setText(R.string.save);
        initRadio();
        initAction();

    }

    private void initRadio() {
        mSexTypeChange.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {

                if (checkedId == R.id.man) {
                   gender="1";

                } else {
                   gender="2";
                }
            }
        });
    }
    private void initAction() {
        mTopBar.rightText.setOnClickListener(this);


    }
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.top_right_txt:
                Downloader.getInstance(this).changeGender(gender,this);

                break;
            default:
                break;
        }
    }

    public <T> void onSuccess(DownloadParams.PARSING_TYPE type, T response, Object obj) {
        super.onSuccess(type, response, obj);

        switch (type) {
            case CHANGE_GENDER:
                toast("修改成功！");
                startActivity(MyInfoActivity.getStartIntent(this));
                break;

            default:
                break;

        }

    }

}

